//
//  HJMainTabBarVC.swift
//  Weibo
//
//  Created by 韩佳 on 16/4/16.
//  Copyright © 2016年 ddg. All rights reserved.
//

import UIKit

class HJMainTabBarVC: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //赋值自定义的tabBar
        let tabBar = HJMainTabBar()
        //点击底部加号按钮调用闭包,注意循环引用
        let composeButtonCloure = { [weak self] in
            let composeView = HJComposeView()
            composeView.show(self)
        }
        tabBar.composeButtonClosure = composeButtonCloure
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(HJHomeTableVC(), title: "首页", imgName: "tabbar_home")
        addChildViewController(HJMessageTableVC(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(HJDiscoveryTableVC(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(HJProfileTableVC(), title: "我", imgName: "tabbar_profile")
        
    }
    
    func addChildViewController(vc: UIViewController, title: String, imgName: String){
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //文字颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        //文字大小
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(11)], forState: .Normal)
        addChildViewController(UINavigationController(rootViewController: vc))
    }
    

}
